﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.Unity;
using Farmacia.BussinessLogic;
using Farmacia.Entities;

namespace Farmacia.net.Almacen.Ubicacion
{
    public partial class frmBuscarUbicacion :BasePage<frmBuscarUbicacion>
    {
        [Dependency]
        public iUbicacionBL UbicacionBL { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {

            var msg = Request.QueryString["msg"];

            if (msg != null)
            {  
                lblMensaje.Text = msg.ToString();
            }

            txtCriterioUbic.Focus();
            
        }

        protected void ODSUbicacion_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
        {

            if (e.Exception != null)
            {
                lblMensaje.Text = e.Exception.Message;
            }

        }

        protected void ODSUbicacion_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = UbicacionBL;
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Eliminar")
            {
                try
                {
                    var row = e.CommandArgument;

                    GridView1.SelectedIndex = Int32.Parse(row.ToString());// Parse(row.ToString());

                    var key = GridView1.SelectedDataKey.Value;
                    UbicacionBL.DeleteUbicacion(Int32.Parse(key.ToString()));
                    
                    //Response.Redirect("frmBuscarCliente.aspx");

                }
                catch (Exception ex)
                {
                    lblMensaje.Text = ex.Message;
                }

                GridView1.DataBind();
            }
        }




    }
}